package com.hong.qrpc.spring.springboot.starter.postprocessor;

import com.hong.qrpc.spring.springboot.starter.annotation.EnableQrpcClient;
import com.hong.qrpc.spring.springboot.starter.annotation.EnableQrpcServer;
import lombok.Data;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author HQT
 * @Date 2022/8/1 19:57
 */
@Data
@Component
public class QrpcImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    private static Map<String, Object> clientAttrs;
    private static Map<String, Object> serverAttrs;

    @Override
    public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) {
        clientAttrs = metadata.getAnnotationAttributes(EnableQrpcClient.class.getCanonicalName());
        serverAttrs = metadata.getAnnotationAttributes(EnableQrpcServer.class.getCanonicalName());
    }

    public static Map<String, Object> getClientAttrs() {
        return clientAttrs;
    }

    public static Map<String, Object> getServerAttrs() {
        return serverAttrs;
    }
}
